<template>
	<view>
		<view class="nickbox">
			<text>昵称</text>
			<view class="inpbox">
				<input type="text" placeholder="请输入昵称" v-model="nickname" />
			</view>
		</view>

		<view class="btnbox" @click="setname">
			保存
		</view>
	</view>
</template>

<script>
	import ikz from '@/pages/Common/tools.js'
	export default {
		data( ) {
			return {
				nickname: '',
				avatarban:''
			};
		},
		onLoad( ) {
			this.nickname = uni.getStorageSync( 'user_info' ).nickname || ''
			this.avatarban = uni.getStorageSync( 'user_info' ).avatarban || ''
		},
		methods: {
			setname() {
				let path = '/xyb/user_wechat/update_nickname_avatar'
				let data = {
					token: uni.getStorageSync( 'local_user_session' ),
					nickname: this.nickname,
					avatar:this.avatarban
				}
				ikz.requestPost( path, data, res => {
					if ( res.data.code == 1 ) {
						let title = ''
						if ( this.first == 'true' ) {
							title = '设置成功'
						} else {
							title = '修改成功'
						}
						uni.setStorageSync( 'user_info', res.data.data.user_info )
						getApp( ).globalData.mobile = res.data.data.user_info.mobile
						uni.showToast( {
							title,
							icon: 'none',
						} )
						setTimeout( ( ) => {
							if ( this.first == 'true' ) {
								uni.reLaunch( {
									url: '/pages/Home/index',
								} )
							} else {
								uni.navigateBack( )
							}
						}, 2000 )
					} else {
						uni.showToast( {
							title: res.data.msg,
							icon: "none",
							duration: 2000
						} )
					}
				} )
			}
		},
	}
</script>

<style lang="scss">
	.nickbox {
		padding: 22rpx 30rpx;
		box-sizing: border-box;

		text {
			height: 44rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
			text-align: left;
		}

		.inpbox {
			width: 690rpx;
			height: 100rpx;
			background: #F7F7F7;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			padding: 0 16rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			input {
				width: 690rpx;
				height: 100rpx;
			}
		}
	}

	.btnbox {
		width: 454rpx;
		height: 88rpx;
		background: #247EFF;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		// margin-top: 180rpx;
		font-weight: 400;
		font-size: 30rpx;
		line-height: 88rpx;
		color: #FFFFFF;
		text-align: center;
		margin: 180rpx auto;
	}
</style>